﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;

namespace EasyTrader
{
    public class CPSvr8111STable : EasyTrader.DataSet.ETDataTable
    {
        public CPSvr8111STable(string a_Name)
            : base(a_Name)
        {
            Init();
        }

        // 여기서 행을 추가해 준다.
        public void Init()
        {
            AddColumn("BarIndex");
            AddColumn("DayIndex");
            AddColumn("시각");
            AddColumn("차익매수금액");
            AddColumn("차익매도금액");
            AddColumn("비차익매수금액");
            AddColumn("비차익매도금액");
            AddColumn("차익순매수금액");
            AddColumn("비차익순매수금액");
            AddColumn("전체순매수금액");
        }

        // 최초의 값들을 저장한다.
        public object[] firstVal = new object[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

        public double GetOpenVal(string a_ColName)
        {
            double openVal = 0;
            if (a_ColName == "차익매수금액")
            {
                openVal = Convert.ToDouble(firstVal[3]);
            }
            else if (a_ColName == "차익매도금액")
            {
                openVal = Convert.ToDouble(firstVal[4]);
            }
            else if (a_ColName == "비차익매수금액")
            {
                openVal = Convert.ToDouble(firstVal[5]);
            }
            else if (a_ColName == "비차익매도금액")
            {
                openVal = Convert.ToDouble(firstVal[6]);
            }
            else if (a_ColName == "차익순매수금액")
            {
                openVal = Convert.ToDouble(firstVal[7]);
            }
            else if (a_ColName == "비차익순매수금액")
            {
                openVal = Convert.ToDouble(firstVal[8]);
            }
            else if (a_ColName == "전체순매수금액")
            {
                openVal = Convert.ToDouble(firstVal[9]);
            }
            
            return openVal;
        }

        public override void SaveTableToXml()
        {
            /*
            DateTime now = DateTime.Now;
            int year = now.Year;
            int month = now.Month;
            int day = now.Day;
            string fileName = Directory.GetCurrentDirectory();
            fileName += "\\";
            fileName += year.ToString() + "_";
            fileName += month.ToString() + "_";
            fileName += day.ToString() + "_";
            fileName += "CPSvr8111SOpen.txt";
            GlobalVar.SaveArrayData(fileName, firstVal);
             */
            // 여기서 할 일을 한다.
            base.SaveTableToXml();
        }

        public override void ReadFromXml(DateTime a_DateTime)
        {
            GlobalVar.CPSvr8111SDataDownloaded = true;
            base.ReadFromXml(a_DateTime);
        }
    }
}
